#!/bin/sh

################################################################################
# Copyright 1999-2010 by Nice, srl.,
# Via Milliavacca, 9
# 14100 Asti (AT) - ITALY
# All rights reserved.
#
# This software is the confidential and proprietary information
# of Nice, srl. ("Confidential Information").
# You shall not disclose such Confidential Information
# and shall use it only in accordance with the terms of
# the license agreement you entered into with Nice.
################################################################################

#------------------------------------------------------------------
# Upload files
#
# Usage: fm.upload <path> <files>
#
# - path:  the current path (relative to vroot)
# - files: files to be downloaded (one per line)
#
#------------------------------------------------------------------

. "${EF_ROOT}/plugins/irods/bin/common"
. "${EF_ROOT}/plugins/fm/fm/backends/common"

if [ -z "$1" ]; then
  fatal "Cannot upload file(s)" "Missing input parameter: current path"
fi

if [ -z "$2" ]; then
  # No file to be uploaded
  exit 0
fi

_fullpath="$1"

# Change to the required directory
${IRODS_ICOMMANDS_DIR}/icd "${_fullpath}" >/dev/null 2>&1
if [ $? -ne 0 ]; then
  fatal "Cannot upload the selected file(s)" "Cannot access to working directory"
fi

_message="`${IRODS_ICOMMANDS_DIR}/iput -fk \"${2}\" \"${_fullpath}\" 2>&1`"
if [ $? -ne 0 ]; then
  error "Cannot upload file ${_not_uploaded}" "`trim ${_message}`"
fi

# ex:ts=2:et:
